/*!
    \copyright  Copyright (c) 2019 - 2025 Qualcomm Technologies International, Ltd.
                All Rights Reserved.
                Qualcomm Technologies International, Ltd. Confidential and Proprietary.
    \file
    \ingroup    ui_indicator
    \brief      
*/

#include "ui_indicator_log_level.h"
#include "ui_indicator_prompts.h"
#include "ui.h"
#include "ui_indicator_private.h"
#include "ui_indicator.h"

#include <logging.h>
#include <panic.h>

extern ui_prompts_task_data_t the_prompts;

bool uiPrompts_GetPromptIndexFromMappingTable(MessageId id, uint16 *prompt_index)
{
    return UiIndicator_GetIndexFromMappingTable(
                the_prompts.sys_event_to_prompt_data_mappings,
                the_prompts.mapping_table_size,
                id,
                prompt_index);
}

const ui_prompt_data_t * uiPrompts_GetDataForPrompt(MessageId sys_event)
{
    uint16 prompt_index;
    if ( uiPrompts_IsUserHandledPrompt(sys_event) )
    {
        return uiPrompts_GetDataForUserPrompt(sys_event);
    }
    else if ( uiPrompts_GetPromptIndexFromMappingTable(sys_event, &prompt_index) )
    {
        return &UiIndicator_GetDataForIndex(
                    the_prompts.sys_event_to_prompt_data_mappings,
                    the_prompts.mapping_table_size,
                    prompt_index)->prompt;
    }
    return NULL;
}

bool uiPrompts_IsPromptMandatory(MessageId sys_event)
{
    uint16 prompt_index;
    if ( uiPrompts_IsUserHandledPrompt(sys_event) )
    {
        const ui_event_indicator_table_t *prompt_to_play = uiPrompts_GetDataForUserEvent(sys_event);
        return prompt_to_play->await_indication_completion;
    }
    else if ( uiPrompts_GetPromptIndexFromMappingTable(sys_event, &prompt_index) )
    {
        ui_event_indicator_table_t prompt_to_play = the_prompts.sys_event_to_prompt_data_mappings[prompt_index];
        return prompt_to_play.await_indication_completion;
    }
    Panic();
    return FALSE;
}

bool uiPrompts_IsPromptPlayAlways(MessageId sys_event)
{
    uint16 prompt_index;
    if ( uiPrompts_IsUserHandledPrompt(sys_event) )
    {
        const ui_event_indicator_table_t *prompt_to_play = uiPrompts_GetDataForUserEvent(sys_event);
        return prompt_to_play->data.prompt.play_always;
    }
    else if ( uiPrompts_GetPromptIndexFromMappingTable(sys_event, &prompt_index) )
    {
        ui_event_indicator_table_t prompt_to_play = the_prompts.sys_event_to_prompt_data_mappings[prompt_index];
        return prompt_to_play.data.prompt.play_always;
    }
    return FALSE;
}

bool uiPrompts_IsPromptLocalOnly(MessageId sys_event)
{
    uint16 prompt_index;
    if ( uiPrompts_IsUserHandledPrompt(sys_event) )
    {
        const ui_event_indicator_table_t *prompt_to_play = uiPrompts_GetDataForUserEvent(sys_event);
        return prompt_to_play->data.prompt.local_playback_only;
    }
    else if ( uiPrompts_GetPromptIndexFromMappingTable(sys_event, &prompt_index) )
    {
        ui_event_indicator_table_t prompt_to_play = the_prompts.sys_event_to_prompt_data_mappings[prompt_index];
        return prompt_to_play.data.prompt.local_playback_only;
    }
    return FALSE;
}

void UiPrompts_SetPromptConfiguration(const ui_event_indicator_table_t *table, uint8 size)
{
    the_prompts.sys_event_to_prompt_data_mappings = table;
    the_prompts.mapping_table_size = size;

    UiIndicator_RegisterInterestInConfiguredSystemEvents(
                the_prompts.sys_event_to_prompt_data_mappings,
                the_prompts.mapping_table_size,
                &the_prompts.task);
}